<?php
/**
 * 店铺控制器
 * 
 * @version $Id: Shop.php 679 2013-02-20 02:28:13Z linsir123 $
 */
class controllerShop extends AppController 
{
	/**
	 * 店铺明细
	 */
	public function actionInfo()
	{
		$sellerId = $this->_getSellerId();
		$nick = $this->_getNick();
		
		///
		$mItem = M::item();
		$mShop = M::shop();
		
		///
		$shop = $mShop->getOne($nick);
		$list = $mItem->getPShop($sellerId);
		$shops = $mShop->getRelate($nick, 9);
		$keyMeta = $shop['nick'];
		foreach ($shops as $v) 
			$keyMeta .= ",". $v['nick'];
			
		///
		AppView::addCss('themes/01/shop.css');
		View::display('shop/index');
		View::assignSet(array(
			'shop' => $shop, 
			'shops' => $shops, 
			'list' => $list, 
			'keyMeta' => $keyMeta, 
		));
	}
	
	/**
	 * 页面跳转
	 */
	public function actionJump()
	{
		$nick = $this->_getNick();
		
		/// 日志
		$this->log('Jump', null);
		
		///
		View::display('shop/jump');
		View::assignSet(array(
			'nick' => $nick
		));
	}
	
	
	/// 以下为私有方法 ///
	
	
	/**
	 * 取得店铺呢称
	 */
	private function _getNick()
	{
		$nick = trim($_GET['nick']);
		if ( ! empty($nick)) {
			$tmp = iconv("UTF-8", "UTF-8", $nick);
			if ($tmp != $nick) 
				$nick = iconv("GBK", "UTF-8", $nick);
		}
		
		///
		return $nick;
	}
	
	/**
	 * 
	 */
	private function _getSellerId()
	{
		$sellerId = trim($_GET['seller_id']);
		if ( ! preg_match("/^[\d]+$/", $sellerId) || ! is_numeric($sellerId)) 
			$this->goto301();
			
		///
		return $sellerId;
	}
}
